home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-29 | 3.0 KB | 118 lines | [TEXT/KAHL] |
- #include <Retrace.h>
- #include <Devices.h>
- #include <SegLoad.h>
- #include <Timer.h>
-
- #include <math.h>
- #include <iostream.h>
-
- #include "C_randomizer.h"
- #include "flowsettings.h"
- #include "vretrace.h"
- // #include "macutilities.h"
- #include "phaser.h"
- #include "screenarea.h"
- #include "screendots.h"
- #include "dotcollection.h"
- #include "movingnoisedots.h"
-
- movingnoisedots::movingnoisedots( int numbits,
- int xpos, int ypos, int aantaldots, int lifetime, int noiseBits)
- : dotcollection( aantaldots)
- , phaser( lifetime)
- , screendots( numbits, xpos, ypos, aantaldots)
- , noiseMask( 0x00010001L * ((1 << noiseBits) - 1))
- , noiseShift( (1 << noiseBits) >> 1)
- {}
-
- movingnoisedots::movingnoisedots( int numbits,
- screen_position where, int aantaldots, int lifetime, int noiseBits)
- : dotcollection( aantaldots)
- , phaser( lifetime)
- , screendots( numbits, where, aantaldots)
- , noiseMask( 0x00010001L * ((1 << noiseBits) - 1))
- , noiseShift( (1 << noiseBits) >> 1)
- {}
-
- void movingnoisedots::compute_addresses()
- {
- move_the_dots();
- //
- // could use dotcollection::numdots, as well
- //
- #define help_the_optimizer
-
- #ifdef help_the_optimizer
- const int loopend = screendots::numdots;
- const int the_shift = coord_shift; // aids the optimizer
- unsigned char **dot_address = dot_addresses;
- short *xcoord = xcoords;
- short *ycoord = ycoords;
- for( int i = 0; i < loopend; i++)
- {
- *dot_address++ =
- &screen[ *ycoord++ >> the_shift][ *xcoord++ >> the_shift];
- }
- #else
- for( int i = 0; i < screendots::numdots; i++)
- {
- dot_addresses[ i] =
- &screen[ ycoords[ i] >> coord_shift][ xcoords[ i] >> coord_shift];
- }
- #endif
- #undef help_the_optimizer
- }
-
- void movingnoisedots::move_the_dots()
- {
- (void)major_step();
-
- short *the_xcoord = xcoords;
- short *the_ycoord = ycoords;
- //
- // Note: there is _exactly_ one '*the_xcoord++ = …' and _exactly_ one
- // '*the_ycoord++ = …' in every possible path through the loop.
- //
- short_long_hack the_hack;
- const int loopend = dotcollection::numdots; // could also use screendots::numdots
-
- for( int i = 0; i < loopend; i++)
- {
- if( minor_step() != 0)
- {
- //
- // compute new position of dot
- //
- const long prev_x = (long) *the_xcoord;
- const long prev_y = (long) *the_ycoord;
- //
- // determine a direction to move in:
- // (for now, we simply choose a fixed noise level and use that)
- //
- the_hack.ulong = randomizer_step() & noiseMask;
- const long new_x = ((long) *the_xcoord) + (long)the_hack.shorties.left - noiseShift;
- const long new_y = ((long) *the_ycoord) + (long)the_hack.shorties.right - noiseShift;
-
- if( (new_x != (short)new_x) || (new_y != (short)new_y))
- {
- //
- // use one call of 'step' and split the result in two:
- //
- the_hack.ulong = randomizer_step();
- *the_xcoord++ = the_hack.shorties.left;
- *the_ycoord++ = the_hack.shorties.right;
- } else {
- *the_xcoord++ = new_x;
- *the_ycoord++ = new_y;
- }
- } else {
- //
- // dot surpassed its lifetime
- //
- the_hack.ulong = randomizer_step();
- *the_xcoord++ = the_hack.shorties.left;
- *the_ycoord++ = the_hack.shorties.right;
- }
- }
- }
-